<?php
/**
 * Head First 设计模式
 * 第二章： 观察者模型
 * 气象站例子 ── 布告板
 */
include_once 'interface.php';


/**
 * 普通的天气公告板
 */
class CurrentConditionsDisplay implements Observer, DisplayElement {
	/**
	 * 温度、湿度
	 */
	private $temperature;
	private $humidity;
	
	/**
	 * 服务主题对象
	 */
	private $weatherData;
	
	/**
	 * 注册成为观察者
	 */
	public function __construct(Subject $weatherData) {
		$this->weatherData = $weatherData;
		$this->weatherData->registerObserver($this);
	} //END func __construct

	/**
	 * @see DisplayElement::display()
	 *
	 */
	public function display() {
		echo "Current Condition: ".$this->temperature."F degrees and ".$this->humidity."% humidity.";
	} //END func display
	
	/**
	 * @see Observer::update()
	 *
	 * @param float $temperature
	 * @param float $humidity
	 * @param float $pressure
	 */
	public function update($temperature, $humidity, $pressure) {
		$this->temperature = $temperature;
		$this->humidity = $humidity;
		$this->display();
	} //END func update
	  
}
?>